package com.zhang.multition.example;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2022-02-28 18:41
 * To: 真常应物，真常得性，常清常静，常清静矣
 */
public class Emperor {
    private static int maxNumOfEmperor = 2;
    private static ArrayList emperorInfoList = new ArrayList(maxNumOfEmperor);
    private static ArrayList emperorList = new ArrayList(maxNumOfEmperor);
    private static int countNumOfEmperor = 0;
    // 只能有这两个皇帝，不允许在产生了
    static{
        for (int i = 0; i < maxNumOfEmperor; i++) {
            emperorList.add(new Emperor("皇"+(i+1)+"帝"));
        }
    }
    private Emperor(){

    }
    private Emperor(String info){
        emperorInfoList.add(info);
    }
    // 随机参拜皇帝
    public static Emperor getInstance(){
        Random random = new Random();
        countNumOfEmperor = random.nextInt(maxNumOfEmperor);
        return (Emperor) emperorList.get(countNumOfEmperor);
    }
    // 只参拜某个皇帝
    public static Emperor getInstance(int i){
        if (i>=0 && i<2){
            countNumOfEmperor = i;
            return (Emperor) emperorList.get(countNumOfEmperor);
        }else{
            System.out.println("无这个皇帝");
            return new Emperor();
        }
    }
    public static void emperorInfo(){
        System.out.println(emperorInfoList.get(countNumOfEmperor));
    }

}
